package com.heima.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.heima.dao.CustomerMapper;
import com.heima.dao.DictMapper;
import com.heima.pojo.BaseDict;
import com.heima.pojo.Customer;
import com.heima.pojo.QueryVo;
import com.heima.pojo.Result;

@Service
public class CustomerService {
	
	@Resource
	DictMapper dictMapper;
	
	@Resource
	CustomerMapper customerMapper;
	
	public List<BaseDict> findDictByTypeCode(String typeCode) {
		List<BaseDict> list = dictMapper.findDictByTypeCode(typeCode);
		return list;
	}
	
	public List<Customer> findCustomerList(QueryVo vo) {
		List<Customer> list = customerMapper.findCustomerList(vo);
		return list;
	}
	
	public Integer findCustomerCount(QueryVo vo) {
		Integer customerCount = customerMapper.findCustomerCount(vo);
		return customerCount;
	}
	
	public Result deleteCustomerById(Integer id) {
		try {
			customerMapper.deleteCustomerById(id);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return new Result(false, "删除失败");
	}
	
	public Customer findCustomerById(Integer id) {
		Customer customer = customerMapper.findCustomerById(id);
		return customer;
	}
	
	public Result updateCustomerById(Customer customer) {
		try {
			customerMapper.updateCustomerById(customer);
			return new Result(true, "修改成功");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return new Result(false, "修改失败");
	}
	
}
